<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\User;
use think\Request;

class Usermanage extends Controller
{
  protected $user = null;

  function __construct()
  {
    $this->user = new User();
  }

//  获取用户数据
  function getUser(){
    return res(1000, '获取成功',$this->user->select());
  }

//  修改用户状态
  function changeState(){
    $res = getPost();
    $state = $res['state'];
    $acc = $res['acc'];

    $result = $this->user->changeState($state,$acc);
    if ($result == 0){
      return res(1001, '状态修改失败');
    }else{
      return res(1000, '状态修改成功');
    }
  }

  //修改用户信息
  function edit(){

    $res = getPost();
    $acc = $res['acc'];
    $nickname = $res['nickname'];
    $pwd = $res['pwd'];
    $md5Pwd = myMd5($pwd);
    $desc = $res['desc'];
    $phone = $res['phone'];
    $address = $res['address'];


    $result = $this->user->edit($acc,$nickname,$md5Pwd,$desc,$phone,$address);

    if ($result == 0){
      return res(1001, '状态修改失败');
    }else{
      return res(1000, '状态修改成功');
    }

  }

  //用户信息模糊查询
  function searchUser(){
    $res = getPost();
    $searchWord = $res['searchWord'];

    $newSearchWord = explode("，",$searchWord);//分解用户输入的多个关键词

    $result = $this->user->search($newSearchWord);

    if($result){
      return res(1000,"查询成功",$result);
    }else{
      return res(1001,"查询失败");
    }
  }

}
